<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }

  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }

  .rj-cell.max span {
    font-size: 16px;
    padding-right: 20px;
  }

  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }

  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

  .weui-cells {
    margin-top: 0;
  }

  .weui-cells_form {
    background: #fbfbfb;
  }

  .weui-cell {
    background: #fff;
  }

  .weui-cells__title {
    text-align: left;
  }

  .oitem {
    padding: 3px;
  }

  .hide {
    display: none;
  }

  #acts {
    font-size: 0;
  }

  #acts span {
    font-size: 14px;
  }

  .halfbtn {
    display: inline-block;
    width: 49%;
  }

  .weui-label {
    text-align: left;
  }

  .time {
    border: none;
    font-size: 17px;
  }

  .weui-cell_select {
    padding: 10px 15px;
  }

  .weui-select {
    height: auto;
    line-height: normal;
  }


  .weui_uploader_input_wrp {
    float: left;
    position: relative;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 77px;
    height: 77px;
    border: 1px solid #D9D9D9;
  }

  .weui_uploader_hd {
    padding-top: 0;
    padding-right: 0;
    padding-left: 0;
  }

  .weui_uploader_files {
    list-style: none;
  }

  .weui_uploader_input_wrp:before {
    width: 2px;
    height: 39.5px;
  }

  .weui_uploader_input_wrp:before, .weui_uploader_input_wrp:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    background-color: #D9D9D9;
  }

  .weui_uploader_input {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }

  .weui_uploader_input_wrp:after {
    width: 39.5px;
    height: 2px;
  }

  .weui_uploader_bd {
    overflow: hidden;
  }

  .weui_cell {
    padding: 10px 15px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .outstore >>> .weui-uploader_files {
    list-style: none;
    overflow-y: hidden;
  }

  .outstore >>> .weui-uploader_file {
    float: left;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 79px;
    background: no-repeat 50%;
    background-size: cover;
  }

  .weui-cell.fir {
    border-top: 0;
  }

  .help {
    text-align: right;
    padding: 5px;
    font-size: 12px;
    color: #bbb;
  }

  .weui_uploader_input_wrp.inrow {
    width: 30px;
    height: 30px;
    margin: 0;
  }

  .weui_uploader_input_wrp:before {
    height: 19.5px;
  }

  .weui_uploader_input_wrp:after {
    width: 19.5px;
  }

  .weui-uploader_file.inrow {
    margin: 0;
    width: 40px;
  }

  li.weui-uploader_file {
    display: inline-block;
    padding: 3px 5px;
  }

  ul#images {
    text-align: right;
  }

  .addwrap >>> .ui.selection.dropdown {
    border: none;
  }

  .addwrap >>> .ui.dropdown .menu > .item {
    font-size: 18px;
  }

  .addwrap >>> .ui.search.dropdown > .text {
    font-size: 18px;
  }
</style>
<template>
  <div class="addwrap" style="overflow: hidden;">
    <div
      style="height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      录入采收合同
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px"/>
      </a>
    </div>
    <div class="weui-cells weui-cells_form">
      <form action="" method="post" id="formid">
        <div class="cellgroup">
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">名称</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" name="name" ref="name">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">采收方式</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="type" v-model="htype">
                <option value="">请选择</option>
                <option value="1">地头采收</option>
                <option value="2">库房采收</option>
              </select>
            </div>
          </div>
          <div class="cellgroup">
            <div class="weui-cell">
              <div class="weui-cell__hd"><label class="weui-label">采收类型</label></div>
              <div class="weui-cell__bd">
                <select class="weui-select" name="harvestType" v-model="harvestType">
                  <option value="">请选择</option>
                  <option value="1">订单户</option>
                  <option value="2">临采</option>
                </select>
              </div>
            </div>
            <div class="weui-cell" v-if="harvestType == 2">
              <div class="weui-cell__hd"><label class="weui-label">采收数量</label></div>
              <div class="weui-cell__bd">
                <input class="weui-input inlinput1" type="text" name="weight" v-model="weight" placeholder="请输入" required />
                <input class="weui-input inlinput2" type="text" readonly value="吨" />
              </div>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">采收主体</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" class="weui-input" name="parta" :value="parta.name"/>
              <input type="hidden" name="organizationid" :value="parta.guid"/>
              <select class="weui-select" name="" v-model="parta">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in companys" :value="item">
                  {{ item.name }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">部门</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="departid" :value="depart.guid"/>
              <input type="hidden" name="departname" :value="depart.name"/>
              <select class="weui-select" v-model="depart">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in departments" :key="item.guid" :value="item">
                  {{ item.name }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">入库库房</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="srguid" :value="room.guid"/>
              <input type="hidden" name="srname" :value="room.name"/>
              <select class="weui-select" v-model="room">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in rooms" :key="item.guid" :value="item">
                  {{ item.name }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">质检标准</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="qamainid" v-model="qamain">
                <option value="">请选择</option>
                <option v-for="qamain in qamains" :value="qamain.guid">{{ qamain.qaname }}</option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">乙方</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="partb" :value="partb"/>
              <model-list-select :list="plantors"
                                 v-model="partb"
                                 option-value="guid"
                                 option-text="realname"
                                 placeholder="请选择">
              </model-list-select>
            </div>
          </div>
          <div class="weui-cell" v-if="htype == 2">
            <div class="weui-cell__hd"><label class="weui-label">农户库</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="farmerstoreid" :value="farmerroom.guid"/>
              <input type="hidden" name="farmerstore" :value="farmerroom.name"/>
              <select class="weui-select" v-model="farmerroom">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in farmerRooms" :key="item.guid" :value="item">
                  {{ item.name }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell weui-cell_select" v-if="htype == 1">
            <div class="weui-cell__hd"><label class="weui-label">地块</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="arealandid" ref="arealandid">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in arealands" :key="item.guid" :value="item.guid">
                  {{ item.AName }}
                </option>
              </select>
            </div>
          </div>
        </div>
        <div style="font-size: 0;margin: -6px 0;">
          <div class="weui-cells__title" style="display: inline-block; width: 35%;">付款信息</div>
          <div style="display: inline-block; width: 55%;text-align: right">
            <label for="weuiAgree" class="weui-agree">
              <input id="weuiAgree" type="checkbox" checked name="saveFlage" value="1" class="weui-agree__checkbox">
              <span class="weui-agree__text">
                保存付款信息
              </span>
            </label>
          </div>
        </div>
        <div class="cellgroup">
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">开户行</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" name="bank" v-model="bank"/>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">银行账号</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" name="bankcode" v-model="bankcode"/>
            </div>
          </div>
        </div>
        <div class="weui-cells__title">产品信息</div>
        <div class="cellgroup">
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">产品</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="productguid" :value="product.guid"/>
              <input type="hidden" name="productname" :value="product.productname"/>
              <select class="weui-select" v-model="product">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in products" :key="item.guid" :value="item">
                  {{ item.productname }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">规格</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" name="specificationname" ref="specification"/>
            </div>
          </div>
          <input type="hidden" name="qatype" value="1">
          <!--            <div class="weui-cell">-->
          <!--              <div class="weui-cell__hd"><label class="weui-label">质检方式</label></div>-->
          <!--              <div class="weui-cell__bd">-->
          <!--                <select class="weui-select" name="qatype" ref="qatype">-->
          <!--                  <option value="1" selected>库房质检</option>-->
          <!--&lt;!&ndash;                  <option value="2">地头质检</option>&ndash;&gt;-->
          <!--                </select>-->
          <!--              </div>-->
          <!--            </div>-->
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">支付方式</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="paymentmethod" v-model="paymentmethod">
                <option value="1" :disabled="currQamainType == 2">装车付</option>
                <option value="2">验收付</option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">扣杂方式</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="deducttype" v-model="deducttype">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in deducttypes" :key="item.dictkey" :disabled="packDeduct(item.dictkey)"
                        :value="item.dictkey">
                  {{ item.dicttext }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell" v-if="deducttype == 1">
            <div class="weui-cell__hd"><label class="weui-label">扣杂标准</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="isdiscount" v-model="isdiscount">
                <option v-for="(item, index) in isdiscounts"
                        v-if="item.dictkey == 1 || item.dictkey == 2 ||  item.dictkey == 3"
                        :disabled="packIsdist(item.dictkey)" :value="item.dictkey">
                  {{ item.dicttext }}
                </option>
                <!--                  <option value="">请选择</option>-->
                <!--                  <option value="1"> 按照合同约定的扣杂率扣杂</option>-->
                <!--                  <option value="2" :disabled="paymentmethod == 1">按照质检结果扣杂</option>-->
                <!--                  <option value="3" :disabled="paymentmethod == 1"> 合同和质检结果取最大扣杂</option>-->
                <!-- lrj-0831 将选项4放到分步扣杂下-->
                <!--                  <option value="4" :disabled="paymentmethod == 1">按质检结果分级扣杂</option>-->
              </select>
            </div>
          </div>
          <div class="weui-cell" v-if="deducttype == 2">
            <div class="weui-cell__hd"><label class="weui-label">扣杂标准</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="isdiscount" v-model="isdiscount">
                <option v-for="(item, index) in isdiscounts" v-if="item.dictkey == 5 ||  item.dictkey == 6"
                        :disabled="packIsdist(item.dictkey)" :value="item.dictkey">
                  {{ item.dicttext }}
                </option>
                <!--                  <option value="">请选择</option>-->
                <!--                  <option value="4" :disabled="paymentmethod == 1">按质检结果分级扣杂</option>-->
                <!--                  <option value="6" :disabled="paymentmethod == 1">优质优价</option>-->
              </select>
            </div>
          </div>
          <div class="weui-cell" v-if="deducttype == 1">
            <div class="weui-cell__hd"><label class="weui-label">扣杂率(%)</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" name="discountrate" ref="discountrate">
            </div>
          </div>
          <input type="hidden" name="setlwgtype" value="2"/>
          <div class="weui-cell" v-if="isdiscount == 6">
            <div class="weui-cell__hd"><label class="weui-label">区域</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="region" :value="region.dictkey"/>
              <input type="hidden" name="regionName" :value="region.dicttext"/>
              <select class="weui-select" v-model="region">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in regions" :key="item.dictkey" :value="item">
                  {{ item.dicttext }}
                </option>
              </select>
            </div>
          </div>
          <input type="hidden" name="region" value="" v-if="isdiscount != 6"/>
          <input type="hidden" name="regionName" value="" v-if="isdiscount != 6"/>
          <div class="weui-cell" v-if="isdiscount == 6">
            <div class="weui-cell__hd"><label class="weui-label">系列</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="series" :value="serie.dictkey"/>
              <input type="hidden" name="seriesName" :value="serie.dicttext"/>
              <select class="weui-select" v-model="serie">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in series" :key="item.dictkey" :value="item">
                  {{ item.dicttext }}
                </option>
              </select>
            </div>
          </div>
          <input type="hidden" name="series" value="1" v-if="isdiscount != 6"/>
          <input type="hidden" name="seriesName" value="" v-if="isdiscount != 6"/>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">单价</label></div>
            <div class="weui-cell__bd">
              <template v-if="currQamainType == 2">
                <input class="weui-input inlinput0" type="number" name="price" :value="price" readonly ref="price">
                <input class="weui-input  inlinput3" type="text" value="元/淀粉含量*吨">
                <p v-if="price == ''" style="font-size: 12px;text-align: right;margin-right: 10px;margin-left: 15px;color: red;">没有获取到淀粉薯采收单价</p>
              </template>
              <template v-else>
                <input class="weui-input inlinput0" type="number" name="price" ref="price">
                <input class="weui-input inlinput3" type="text" value="元/吨">
              </template>
            </div>
          </div>
        </div>
        <div v-if="isdiscount == 5 || isdiscount == 6">
          <div class="oitem" v-for="(currStandard, itemNo) in packIsval(standards)">
            <template v-if="currStandard.isvaluation == 1">
              <div class="weui-cells__title">扣杂分级标准{{ itemNo + 1 }}</div>
              <div class="weui-cell weui-cell_select fir">
                <div class="weui-cell__hd"><label class="weui-label">分级标准</label></div>
                <div class="weui-cell__bd">
                  <input type="hidden" :name="'standars[' + itemNo + '].standard'" :value="currStandard.standard">
                  <input type="hidden" :name="'standars[' + itemNo + '].standardid'" :value="currStandard.guid">
                  <select class="weui-select standard">
                    <option :value="currStandard" selected>{{ currStandard.standard }}</option>
                  </select>
                </div>
              </div>
              <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">单价</label></div>
                <div class="weui-cell__bd">
                  <input class="weui-input inlinput1 price" type="number" :name="'standars[' + itemNo + '].price'"
                         placeholder="请输入单价">
                  <input class="weui-input inlinput2" type="text" value="元/吨">
                </div>
              </div>
            </template>
          </div>
        </div>
        <div class="weui-btn-area">
          <a class="weui-btn weui-btn_primary subbtn" href="javascript:" @click="postForm()">提交</a>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
  import 'vue-search-select/dist/VueSearchSelect.css'
  import {ModelListSelect} from 'vue-search-select'
  import ContractItem from "./ContractItem";

  export default {
    name: 'AddProContract',
    data() {
      return {
        username: localStorage.username,
        userid: localStorage.userid,
        batches: [],
        bitchid: '',
        plantors: [],
        partb: '',
        bankcode: '',
        bank: '',
        arealands: [],
        arealandid: '',
        products: [],
        product: '',
        specs: [],
        specification: '',
        deducttypes: [],
        deducttype: 1,
        isdiscounts: [],
        isdiscount: '',
        parta: '',
        companys: '',
        rooms: [],
        room: '',
        farmerRooms: [],
        farmerroom: '',
        departments: [],
        depart: '',
        setlwgtype: 1,
        paymentmethod: 2,
        batch: '',
        standards: '',
        oitems: [0],
        qamains: '',
        qamain: '',
        htype: 1,
        supplyers: [],
        supplyerid: '',
        supplyer: '',
        series: [],
        serie: '',
        regions: [],
        region: '',
        weight: '',
        harvestType: '',
        artoken: '',
        currQamainType: '',
        price: ''
      }
    },
    components: {ModelListSelect, ContractItem},
    mounted() {
      this.getOrgs();
      this.getPlantors();
      this.getProducts();
      this.getSpecs();
      this.getDepartment();
      // this.getBatches();
      this.getQamains();
      this.getSeries();
      this.getRegions();
      this.getDeductypes();
      this.getIsdiscounts();
      //根据userid和时间戳生成唯一字符串
      this.artoken = this.createToken();
    },
    watch: {
      parta: function (val) {
        this.getRooms(val.guid);
        this.getPrice(val.guid);
      },
      partb: function (val) {
        if (this.htype == 1) {
          this.getArealands(val);
        } else if (this.htype == 2) {
          this.getFamerRooms();
        }
        this.getSupplyers();
      },
      paymentmethod: function (val) {
        if (val == 1) {
          this.isdiscount = 1;
          this.deducttype = 1;
        }
      },
      deducttype: function (val) {
        if (val == 2) {
          this.isdiscount = 5;
        } else if (val == 1) {
          this.isdiscount = 1;
        }
      },
      isdiscount: function (val) {
        if (val == 5 || val == 6) {
          if (this.standards == '') {
            this.getStandards();
          }
        }
      },
      htype: function (val) {
        if (val == 2) {
          this.getFamerRooms();
        }
      },
      product: function (val) {
        this.serie = this.series.filter(item => {
          return item.dictkey == val.series;
        })[0] || '';
      },
      qamain: function (val) {
        this.currQamainType = this.qamains.filter(item => {
          return item.guid == val;
        })[0].type;
        if (this.currQamainType == 2) {
          this.deducttype = 1;
          // this.isdiscount = 2;
          this.paymentmethod = 2;
          this.getPrice(this.parta.guid);
        }
      },

    },
    methods: {
      packDeduct: function (deduct) {
        let res = false;
        switch (deduct) {
          case 2:
            res =  (this.currQamainType == 2 || this.paymentmethod == 1) ? true : false;
            break;
        }
        return res;
      },
      packIsdist: function (isdis) {
        let res = false;
        switch (isdis) {
          case 2:
            res = this.paymentmethod == 1 ? true : false;
            break;
          case 3:
            res = this.paymentmethod == 1 ? true : false;
            break;
          case 4:
            res = this.paymentmethod == 1 ? true : false;
            break;
          case 6:
            res = this.paymentmethod == 1 ? true : false;
            break;
        }
        return res;
      },
      packIsval: function (standers) {
        if (standers.length == 0) {
          return [];
        }
        return standers.filter(item => {
          return item.isvaluation == 1;
        });
      },
      addItem: function (index) {
        this.oitems.push(index);
      },
      delItem: function () {
        this.oitems.pop();
      },
      getOrgs: function () {
        this.axios({
          method: 'get',
          url: '/harvest/Procurementcontract!getoRs.action',
          params: {}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.companys = response.data.orgs;
          } else {
            this.toastText('获取公司数据失败')
          }
        });
      },
      getPrice: function (orgid) {
        if (this.currQamainType != 2 || !orgid) return;
        this.axios({
          method: 'get',
          url: '/harvest/DpriceApply!getPrice.action',
          params: {orgId: orgid}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.price = response.data.dprice;
            if (!this.price) {
              this.toastText('没有审批通过的单价')
            }
          } else {
            this.toastText('获取淀粉薯单价失败')
          }
        });
      },
      getRooms: function (orgid) {
        this.axios({
          method: 'get',
          url: '/produce/Storeroom!getStoreroom.action',
          params: {'entity.orgguid': orgid}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.rooms = response.data.storeromms;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastText('获取库房数据失败');
          }
        });
      },
      getFamerRooms: function () {
        this.axios({
          method: 'get',
          url: '/produce/Storeroom!getStoreroom.action',
          params: {'entity.farmerid': this.partb}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.farmerRooms = response.data.storeromms;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastText('获取农户库房数据失败');
          }
        });
      },
      getPlantors: function () {
        this.axios({
          method: 'get',
          url: '/harvest/Procurementcontract!getPlanters.action',
          params: {}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.plantors = response.data.planters;
          } else {
            this.toastText('获取种植户数据失败')
          }
        });
      },
      getSupplyers: function () {
        this.axios({
          method: 'get',
          url: '/sales/Supplier!getSupplierByUserId.action',
          params: {userid: this.partb}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.supplyer = response.data.supplier;
            this.bankcode = this.supplyer.bankcode;
            this.bank = this.supplyer.bank;
          } else {
            this.toastText('获取供应商数据失败')
          }
        });
      },
      getBatches: function () {
        this.axios({
          method: 'get',
          url: '/harvest/Procurementbatch!findBatckbyTen.action',
          params: {permission: 38}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.batches = response.data.batchs;
          } else {
            this.toastText('获取批次数据失败')
          }
        });
      },
      getSeries: function () {
        let that = this;
        this.axios({
          method: 'get',
          url: '/sales/Sellform!findDict.action',
          params: {type: 130}
        }).then(response => {
          if (response.statusText == "OK") {
            that.series = response.data;
          } else {
            this.toastText('获取系列数据失败');
          }
        });
      },
      getRegions: function () {
        let that = this;
        this.axios({
          method: 'get',
          url: '/sales/Sellform!findDict.action',
          params: {type: 131}
        }).then(response => {
          if (response.statusText == "OK") {
            that.regions = response.data;
          } else {
            this.toastText('获取区域数据失败');
          }
        });
      },
      getDeductypes: function () {
        let that = this;
        this.axios({
          method: 'get',
          url: '/sales/Sellform!findDict.action',
          params: {type: 132}
        }).then(response => {
          if (response.statusText == "OK") {
            that.deducttypes = response.data;
          } else {
            this.toastText('获取扣杂方式数据失败');
          }
        });
      },
      getIsdiscounts: function () {
        let that = this;
        this.axios({
          method: 'get',
          url: '/sales/Sellform!findDict.action',
          params: {type: 133}
        }).then(response => {
          if (response.statusText == "OK") {
            that.isdiscounts = response.data;
          } else {
            this.toastText('获取扣杂标准数据失败');
          }
        });
      },
      getArealands: function (plantorid) {
        this.axios({
          method: 'get',
          url: '/harvest/Procurementcontract!getArealand.action',
          params: {userid: plantorid}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.arealands = response.data.arealands;
          } else {
            this.toastText('获取地块数据失败')
          }
        });
      },
      getProducts: function () {
        this.axios({
          method: 'get',
          url: '/harvest/Procurementcontract!getProductInfo.action',
          params: {productflag: 1}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.products = response.data.products;
          } else {
            this.toastText('获取产品数据失败')
          }
        });
      },
      getSpecs: function () {
        this.axios({
          method: 'get',
          url: '/harvest/Procurementcontract!getSpecifications.action',
          params: {}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.specs = response.data.specs;
          } else {
            this.toastText('获取产品数据失败')
          }
        });
      },
      getDepartment: function () {
        let that = this;
        this.axios({
          method: 'get',
          responseType: 'json',
          url: '/sales/Sellform!findDepartment.action',
          params: {sPermission: 38}
        }).then(response => {
          if (response.data.status == "true") {
            that.departments = response.data.result;
            this.depart = response.data.result[0];
          } else if (response.data.status == "false") {
            this.toastText(response.data.result);
          } else {
            this.toastText('获取部门数据失败');
          }
        });
      },
      getStandards: function () {
        let that = this;
        this.axios({
          method: 'get',
          responseType: 'json',
          url: '/harvest/Qastandard!getQastandards.action',
        }).then(response => {
          if (response.data.msg == "success") {
            that.standards = response.data.standards;
          } else {
            this.toastText('获取扣杂标准数据失败');
          }
        });
      },
      //扣杂标准
      getQamains: function () {
        let that = this;
        this.axios({
          method: 'get',
          responseType: 'json',
          url: '/trace/Qamain!getQamain.action',
        }).then(response => {
          if (response.data.msg == "success") {
            that.qamains = response.data.qamains;
          } else {
            this.toastText('获取质检标准数据失败');
          }
        });
      },

      //提交表单数据
      postForm: function () {
        let that = this;
        //表单校验
        if (!this.checkFormElm()) {
          return false;
        }
        //防止重复提交
        $('.subbtn').attr("disabled", true).css("pointer-events", "none");
        //显示提交状态
        $.showLoading("正在提交");

        let postData = this.serialize2Obj($("#formid").serializeArray());

        this.axios({
          headers: {
            'artoken': this.artoken
          },
          method: 'post',
          url: '/harvest/Procurementcontract!save.action',
          params: postData
        }).then(response => {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events", "auto");
          //关闭提交状态
          $.hideLoading();

          if (response.data.msg == 'success') {
            this.toastSuccess("保存成功");
            this.$router.push({name: 'ProContractList'});
          } else if (response.data.msg == 'hascontract') {
            this.toastText('该名称合同已存在');
            this.artoken = this.createToken();
          } else if (response.data.msg == 'noBaseFlag') {
            this.toastText('请联系管理员完善该产品的物料信息');
            this.artoken = this.createToken();
          } else if (response.data.msg == 'noEmploy') {
            this.toastText('未分配员工部门');
            this.artoken = this.createToken();
          } else if (response.data.msg == 'noUnitPrice') {
            this.toastText('没有审批通过的淀粉薯单价');
            this.artoken = this.createToken();
          } else {
            this.toastError('系统错误');
            this.artoken = this.createToken();
          }
        }).catch(function (error) {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events", "auto");
          //关闭提交状态
          $.hideLoading();
          that.toastError('系统错误');
          that.artoken = that.createToken();
        });
      },
      checkFormElm: function () {
        if (this.$refs.name && this.$refs.name.value == '') {
          this.toastText('请输入名称');
          return false;
        }
        if (this.harvestType == '') {
          this.toastText('请选择采收类型');
          return false;
        }
        if (this.harvestType == 2 && (this.weight == '' || this.weight <= 0)) {
          this.toastText('采收数量有误');
          return false;
        }
        if (this.htype == 2 && this.farmerroom == '') {
          this.toastText('请选择农户库');
          return false;
        }
        if (this.parta == '' || this.parta == undefined) {
          this.toastText('请选择采收主体');
          return false;
        }
        if (this.depart == '' || this.depart == undefined) {
          this.toastText('请选择部门');
          return false;
        }
        if (this.partb == '') {
          this.toastText('请选择乙方');
          return false;
        }
        if (this.currQamainType == 1 && this.$refs.arealandid && this.$refs.arealandid.value == '') {
          this.toastText('请选择地块');
          return false;
        }
        if (this.bankcode == '') {
          this.toastText('请录入银行账号');
          return false;
        }
        if (this.bank == '') {
          this.toastText('请录入开户行');
          return false;
        }
        if (this.product == '') {
          this.toastText('请选择产品');
          return false;
        }
        if (this.$refs.specification && this.$refs.specification.value == '') {
          this.toastText('请输入规格');
          return false;
        }
        if (this.isdiscount == 6 && !this.region) {
          this.toastText('请选择区域');
          return false;
        }
        if (this.isdiscount == 6 && !this.serie) {
          this.toastText('请选择产品系列');
          return false;
        }
        if (this.currQamainType == 2 && (this.price == '' || this.price == undefined)) {
          this.toastText('单价不能为空');
          return false;
        }
        if (this.currQamainType != 2 && this.$refs.price && this.$refs.price.value == '') {
          this.toastText('请输入单价');
          return false;
        }
        if (this.currQamainType == 2 && this.$refs.price && this.$refs.price.value != '' && parseFloat(this.$refs.price.value) > 100) {
          this.toastText('请纠正您输入的单价，淀粉含量单价高于常规');
          return false;
        }
        if (this.qamain == '') {
          this.toastText('请选择质检标准');
          return false;
        }
        // if (this.$refs.qatype && this.$refs.qatype.value == '') {
        //   this.toastText('请选择质检方式');
        //   return false;
        // }
        if (this.isdiscount == '') {
          this.toastText('请选择扣杂标准');
          return false;
        }
        if (this.deducttype == 1 && this.$refs.discountrate && this.$refs.discountrate.value == '') {
          this.toastText('请输入扣杂率');
          return false;
        }
        if (this.room == '') {
          this.toastText('请选择入库库房');
          return false;
        }
        if (!this.checkEmy('standard')) {
          $.alert('明细分级标准不能为空！');
          return false;
        }
        if (!this.checkEmy2('price')) {
          $.alert('明细单价不能为空！');
          return false;
        }
        return true;
      }
    }
  }
</script>
